<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册 - 物流信息管理系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .register-container {
            max-width: 400px;
            margin: 100px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .register-title {
            text-align: center;
            margin-bottom: 30px;
        }
        .form-floating {
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="register-container">
            <h2 class="register-title">用户注册</h2>
            <form id="registerForm">
                <div class="form-floating">
                    <input type="text" class="form-control" id="username" name="username" placeholder="用户名" required>
                    <label for="username">用户名</label>
                </div>
                <div class="form-floating">
                    <input type="password" class="form-control" id="password" name="password" placeholder="密码" required>
                    <label for="password">密码</label>
                </div>
                <div class="form-floating">
                    <input type="text" class="form-control" id="realName" name="realName" placeholder="真实姓名" required>
                    <label for="realName">真实姓名</label>
                </div>
                <div class="form-floating">
                    <input type="tel" class="form-control" id="phone" name="phone" placeholder="手机号码" required>
                    <label for="phone">手机号码</label>
                </div>
                <div class="d-grid gap-2">
                    <button type="submit" class="btn btn-primary">注册</button>
                    <a href="/login" class="btn btn-link">已有账号？立即登录</a>
                </div>
            </form>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
    <script>
        $(function() {
            $('#registerForm').on('submit', function(e) {
                e.preventDefault();
                
                $.ajax({
                    url: '/api/user/register',
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify({
                        username: $('#username').val(),
                        password: $('#password').val(),
                        realName: $('#realName').val(),
                        phone: $('#phone').val()
                    }),
                    success: function(res) {
                        if (res.code === 200) {
                            alert('注册成功，请登录');
                            window.location.href = '/login';
                        } else {
                            alert(res.msg);
                        }
                    },
                    error: function() {
                        alert('注册失败，请稍后重试');
                    }
                });
            });
        });
    </script>
</body>
</html> 